package ru.passivemoney.indicator;

import java.math.BigDecimal;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ru.passivemoney.root.ContextHolder;

import com.dukascopy.api.IBar;
import com.dukascopy.api.IHistory;
import com.dukascopy.api.IIndicators;
import com.dukascopy.api.JFException;

public abstract class AIndicator {
	
	private static final Logger logger = LoggerFactory.getLogger(AIndicator.class);
	
	protected CommonParameters commonParameters = null;
	protected IndicatorSpecParams specParams = null;
	
	
	public AIndicator(CommonParameters commonParameters, IndicatorSpecParams specParams) {
		super();
		this.commonParameters = commonParameters;
		this.specParams = specParams;
	}

	public void init() {
	}
	
	public abstract BigDecimal getPrognosis() throws JFException ;
	
	public IBar getCurrentBar() {
		try {
			return getHistory().getBar(commonParameters.getInstrument(), commonParameters.getPeriod(), commonParameters.getOfferSide(), commonParameters.getShift());
		} catch (JFException e) {
			logger.error("ERROR wen getting bar. Instrument - {}; period - {}.", commonParameters.getInstrument().toString(), commonParameters.getPeriod().toString());
			logger.error("", e);
		}
		return null;
	}

	public IIndicators getIndicators() {
		return ContextHolder.getContext().getIndicators();
	}

	public IHistory getHistory() {
		return ContextHolder.getContext().getHistory();
	}

	public CommonParameters getCommonParameters() {
		return commonParameters;
	}

	public void setCommonParameters(CommonParameters commonParameters) {
		this.commonParameters = commonParameters;
	}

}
